//
//  WYToolsBar.swift
//  weibo
//
//  Created by 王玉东 on 16/4/13.
//  Copyright © 2016年 wyd. All rights reserved.
//

import UIKit

class WYToolsBar: UIView {
    
    var repostBtn  : UIButton!
    var commentBtn : UIButton!
    var ohYeahBtn  : UIButton!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setUI() {
        repostBtn  = addchildrenBtn("转发", imageName: "timeline_icon_retweet")
        commentBtn = addchildrenBtn("评论", imageName: "timeline_icon_comment")
        ohYeahBtn  = addchildrenBtn("赞", imageName: "timeline_icon_like")
        
        repostBtn.snp_makeConstraints { (make) -> Void in
            make.top.left.bottom.equalTo(self)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.left.equalTo(repostBtn.snp_right)
            make.width.equalTo(repostBtn.snp_width)
        }
        ohYeahBtn.snp_makeConstraints { (make) -> Void in
            make.top.right.bottom.equalTo(self)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(commentBtn.snp_width)
        }
       //创建分割线
        let sep1 = sepView()
        let sep2 = sepView()
        
        let w = 1 / UIScreen.mainScreen().scale
        
        let multiplied = 0.4
        
        sep1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(multiplied)
            make.left.equalTo(repostBtn.snp_right)
            make.width.equalTo(w)
        }
        sep2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(multiplied)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(w)
        }
        
    
    }
    
    private func sepView()->UIView{
    
    let line = UIView()
        line.backgroundColor = UIColor.purpleColor()
        addSubview(line)
        return line
    }
    
    private func addchildrenBtn(title:String,imageName:String) -> UIButton {
    
        let btn = UIButton()
        
        btn.titleLabel?.font = UIFont.systemFontOfSize(12)
        
        btn.setTitle(title, forState: .Normal)
        
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        btn.sizeToFit()
        addSubview(btn)
        return btn
    
    }
    var statusModel: WYStatusModel? {
        didSet{
                repostBtn.setTitle(statusModel?.respostTitle, forState: .Normal)
                commentBtn.setTitle(statusModel?.comentTitle, forState: .Normal)
                ohYeahBtn.setTitle(statusModel?.ohYeahTitle, forState: .Normal)
        
        }
    
    }
    

}
